package com.zz.inventory.controller;

import java.util.List;
import java.io.IOException;

import com.ruoyi.common.core.domain.R;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.zz.inventory.domain.Exams;
import com.zz.inventory.service.IExamsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 考试练习任务Controller
 * 
 * @author zz
 * @date 2025-07-03
 */
@Slf4j
@RestController
@RequestMapping("/exams")
public class ExamsController extends BaseController
{
    @Autowired
    private IExamsService examsService;

    /**
     * 查询考试练习任务列表
     */

    @RequiresPermissions("schoolmanage:exams:list")
    @GetMapping("/list")
    public TableDataInfo getExamsByLabId(
            @RequestParam(required = false) Long labId,
            @RequestParam(required = false) String examName,
            @RequestParam(required = false) String examType,
            @RequestParam(required = false) String status) {

        // 打印接收到的参数
        log.info("请求参数 - labId: {}, examName: {}, examType: {}, status: {}",
                labId, examName, examType, status);

        // 构建查询对象
        Exams exam = new Exams();
        exam.setLabId(labId);
        exam.setExamName(examName);
        exam.setExamType(examType);
        exam.setStatus(status);

        // 分页查询
        startPage();
        List<Exams> list = examsService.selectExamsList(exam);
        return getDataTable(list);
    }

    /**
     * 导出考试练习任务列表
     */
    @RequiresPermissions("schoolmanage:exams:export")
    @Log(title = "考试练习任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Exams exams)
    {
        List<Exams> list = examsService.selectExamsList(exams);
        ExcelUtil<Exams> util = new ExcelUtil<Exams>(Exams.class);
        util.exportExcel(response, list, "考试练习任务数据");
    }

    /**
     * 获取考试练习任务详细信息
     */
//    @RequiresPermissions("schoolmanage:exams:query")
//    @GetMapping(value = "/{examId}")
//    public AjaxResult getInfo(@PathVariable("examId") Long examId)
//    {
//        return success(examsService.selectExamsByExamId(examId));
//    }

    /**
     * 新增考试练习任务
     */
    @RequiresPermissions("schoolmanage:exams:add")
    @Log(title = "考试练习任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Exams exams)
    {
        return toAjax(examsService.insertExams(exams));
    }

    /**
     * 修改考试练习任务
     */
    @RequiresPermissions("schoolmanage:exams:edit")
    @Log(title = "考试练习任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Exams exams)
    {
        return toAjax(examsService.updateExams(exams));
    }

    /**
     * 删除考试练习任务
     */
    @RequiresPermissions("schoolmanage:exams:remove")
    @Log(title = "考试练习任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examIds}")
    public AjaxResult remove(@PathVariable Long[] examIds)
    {
        return toAjax(examsService.deleteExamsByExamIds(examIds));
    }
}
